<?php
/**
 * SimpleCListView class file.
 *
 * @author Chris Sim <monkeymon@gmail.com>
 * @link 
 * @copyright 
 * @license 
 */

Yii::import('zii.widgets.grid.CGridView');
Yii::import('application.widgets.SimpleDropdownColumn');

/**
 * SimpleCListView is a extension of the CListView which add an extra params into rendering the view file 
 * 
 * <pre>
 * $dataProvider=new CActiveDataProvider('Post');
 *
 * $this->widget('zii.widgets.CListView', array(
 *     'dataProvider'=>$dataProvider,
 *     'itemView'=>'_post',   // refers to the partial view named '_post'
 *     'sortableAttributes'=>array(
 *         'title',
 *         'create_time'=>'Post Time',
 *     ),
 * ));
 * </pre>
 *
 */
class SimpleGridView extends CGridView
{
	public $params = array();
	/**
	 * Overiding the original renderItems method
	 */
	public function renderItems()
	{
		echo CHtml::openTag($this->itemsTagName,array('class'=>$this->itemsCssClass))."\n";
		$data=$this->dataProvider->getData();
		if(count($data)>0)
		{
			$owner=$this->getOwner();
			$render=$owner instanceof CController ? 'renderPartial' : 'render';
			if(!is_array($this->params))
				$this->params = array($this->params);
			foreach($data as $i=>$item)
			{
				$data=$this->viewData;
				$data['index']=$i;
				$data['data']=$item;
				$data['widget']=$this;
				$data['params'] = $this->params;
				$owner->$render($this->itemView,$data);
			}
		}
		else
			$this->renderEmptyText();
		echo CHtml::closeTag($this->itemsTagName);
	}
}
